<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
  
        <el-form-item label="帮扶学生姓名" prop="locationName">
          <el-input
            v-model="queryParams.studentName"
            placeholder="请输入帮扶学生姓名"
            clearable
            size="small"
            style="width: 180px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        
  
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <!-- <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            >新增帮扶学生</el-button>
        </el-col> -->
        
        <!-- <el-col :span="1.5">
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['basedata:bclass:remove']"
          >删除</el-button>
        </el-col> -->
  
      </el-row>
  
      <el-table v-loading="loading" :data="bclassList">
        <el-table-column label="被帮扶学生姓名" align="center" width="220" prop="studentName" :show-overflow-tooltip="true" />
        <el-table-column label="牛人姓名" align="center"  prop="helpStudentName" :show-overflow-tooltip="true" />
        <el-table-column label="学生班级" align="center" width="220" prop="className" :show-overflow-tooltip="true" />
        <el-table-column label="帮扶次数" align="center" width="220" prop="helpNum" :show-overflow-tooltip="true" />
        <el-table-column label="提交人" align="center"  prop="createBy" :show-overflow-tooltip="true" />
        <el-table-column label="创建时间" align="center"  prop="createdTime" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
                {{ parseTime(scope.row.createdTime) }}
            </template>
        </el-table-column>
        <el-table-column label="操作" align="center" fixed="right" width="230">
          <template slot-scope="scope">
            <el-button @click="helpListShow(scope.row)" type="text" size="small">帮扶记录</el-button>
            <el-button @click="helpContentShow(scope.row)" type="text" size="small">帮扶情况登记</el-button>
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <el-dialog
        title="帮扶情况登记"
        :visible.sync="helpDialogVisible"
        v-if="helpDialogVisible"
        width="50%"
        height="50%"
        :before-close="handleCloseHelp"
        >
        <el-form :model="formData" label-width="100">
          <el-form-item label="帮扶内容">
            <quill-editor style="margin-left: 100px;"
                v-model="formData.context"
                ref="context"
                :options="editorOption"
            >
            </quill-editor>
          </el-form-item>
        </el-form>
        <div style="text-align: center; margin-top: 80px;">
            <el-button style="margin-top: 12px;" @click="submitHelp" v-loading.fullscreen.lock="loading">提  交</el-button>
            <el-button style="margin-top: 12px;" @click="handleCloseHelp" >关  闭</el-button>
        </div>
      </el-dialog>

      <el-dialog
        title="帮扶记录"
        :visible.sync="helpListDialogVisible"
        v-if="helpListDialogVisible"
        width="50%"
        :before-close="handleCloseHelpList"
        >
        <el-timeline>
            <el-timeline-item
            v-for="(activity, index) in helpList"
            :key="index"
            icon="el-icon-finished"
            color="#0bbd87"
            size="large"
            :timestamp="'提交时间：' +parseTime(activity.createdTime)+'   提交人：' +activity.createBy">
            <div v-html="activity.context"></div>
            </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import {quillEditor} from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
  import {addHelp,pageList,saveHelpInfo,getHelpInfoListByHelpId} from "@/api/evaluation/help"
  
  export default {
    name: "helpList",
    components: {quillEditor},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        stuCount: 0,
        // 字典表格数据
        bclassList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 班主任
        userOptions: [],
        // 状态数据字典
        statusOptions: [],
        // 班级所属部门
        classDeptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          locationPid: 0,
          status: undefined,
          classDept:undefined
        },
        helpDialogVisible:false,
        formData:{
            helpId:null,
            context:null
        },
          // 编辑器配置
        editorOption: {
            placeholder: '在这里输入内容',
            modules: {
            toolbar: [
                ['bold', 'italic', 'underline', 'strike'], //  加粗、倾斜、下划线、删除线
                ['blockquote', 'code-block'],// 引用代码块
                [{'header': 1}, {'header': 2}], // 标题，键值对应的形式，1，2 表示字体大小
                [{'list': 'ordered'}, {'list': 'bullet'}], // 列表
                [{'script': 'sub'}, {'script': 'super'}], // 上下标
                [{'indent': -1}, {'indent': +1}], // 缩进
                [{'direction': 'rtl'}], // 文本方向
                [{'size': ['small', false, 'large', 'huge']}], // 字体大小
                [{'header': [1, 2, 3, 4, 5, 6, false]}], // 几级标题
                [{'color': []}, {'background': []}], // 字体颜色，字体背景颜色
                [{'font': []}], // 字体
                [{'align': []}], // 对齐方式
                ['clean'], //清除
                ['image', 'video'], // 上传图片、上传视频
            ]
            }
        },
        helpList:[],
        helpListDialogVisible:false,
      };
    },
    created() {
      this.getList();
    },
    methods: {
        handleCloseHelpList(){
            this.helpListDialogVisible = false
        },
        helpListShow(row){
            this.helpListDialogVisible=true
            this.selectHelpInfoList(row)
        },
        selectHelpInfoList(row){
            getHelpInfoListByHelpId({helpId:row.id}).then(resp=>{
                this.helpList = resp.data
            })
        },
        submitHelp(){
            saveHelpInfo(this.formData).then(resp=>{
                if(resp.code==200){
                    this.msgSuccess("提交成功")
                    this.handleCloseHelp()
                    this.getList()
                }
            })
        },
        helpContentShow(row){
            this.helpDialogVisible = true
            this.formData.helpId = row.id
        },
        handleCloseHelp(){
            this.helpDialogVisible = false
        },
      /** 查询班级列表 */
      getList() {
        this.loading = true;
        this.bclassList=[]
        pageList(this.queryParams).then(response => {
            this.bclassList = response.data.list;
            this.total = response.data.total;
            this.loading = false;
          }
        );
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
            locationPid:0,
            locationName:null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        if(this.queryParams.locationName){
            this.queryParams.locationPid=null
        }else{
            this.queryParams.locationPid=0
        }
        
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");

        this.handleQuery();
      },
      /** 新增按钮操作 */
      handleAdd(row) {
        this.reset();
        this.open = true;
        this.title = "添加空间位置";
        this.form.locationPid = Number(row.id)
        this.disabledInput=false;
        this.isUpdate = false
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.open = true
        this.isUpdate = true
        this.form = row
        this.form.locationPid = Number(row.locationPid)

      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            addjob(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("提交成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.msgError(response.message);
                }
              });
            
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        const param ={
            jobClassName: row.jobName,
            jobGroupName: row.jobGroupName
        }
        this.$confirm('是否确认删除"' + row.jobName + '"任务吗?', "警告", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
                }).then(function() {
                  return deletejob(param);
                }).then(() => {
                  this.getList();
                  this.msgSuccess("删除成功");
                }).catch(function() {});
  
      },
      handlePause(row){//暂停
        const param ={
            jobClassName: row.jobName,
            jobGroupName: row.jobGroupName
        }
        pausejob(param).then(resp=>{
            this.msgSuccess("暂停成功");
            this.getList();
            
        })
      },
      handleResume(row){//恢复
        const param ={
            jobClassName: row.jobName,
            jobGroupName: row.jobGroupName
        }
        resumejob(param).then(resp=>{
            this.msgSuccess("成功开启");
            this.getList();
            
        })
      }
    }
  };
  </script>
  